<?php

namespace app\index\controller;

use think\Controller;


class Release extends Controller
{

  public function release()
  {

    return $this->fetch();
  }

  public function releaseDetails() //上传信息
  {
    $cate = db('cate')->select();
    $this->assign('cate', $cate);

    if (request()->isPost()) {
      $data = [];

      $data['desc'] = 'none';
      $data['keywords'] = 'none';

      $data['cateid'] = input('fenlei');
      $data['title'] = input('title');
      $data['time'] = input('time');
      $data['author'] = input('author');
      $data['tel'] = input('tel');
      
      $data['price'] = input('price');
      $data['content'] = input('content');

//处理图片

      $pic = request()->file("files");

      if($pic){
        $info=$pic->move(ROOT_PATH.'\public\static'.'\uploads'); //图片保存路径
        if($info){
            // 成功上传后 获取上传信息
            // 输出 jpg
            // echo $info->getExtension();
            // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
            $data['pic'] = str_replace('\\', '/',  $info->getSaveName());
            
            // 输出 42a79759f284b767dfcb2a0197904287.jpg
            // echo $info->getFilename(); 
        }else{
            // 上传失败获取错误信息
            echo $info->getError();
        }

    }
     
     
     
      // $data['pic'] =  $pic->getSaveName();
     

      db('article')->insert($data);
      $this->success('提交成功,即将返回发布页面,您可以继续发布');
    }
    return $this->fetch();
  }
}
